package com.shopx.cm.controller;

import com.shopx.base.anno.ShopxCheckParamAnno;
import com.shopx.cm.dto.CmSendStateDTO;
import com.shopx.cm.dto.CmStateDTO;
import com.shopx.config.model.SysDictModel;
import com.shopx.core.DTO.ExcelObjectDTO;
import com.shopx.core.utils.DateTimeUtil;
import lombok.extern.slf4j.Slf4j;
import com.shopx.base.anno.ShopxParamAnno;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.shopx.base.controller.BaseController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.shopx.cmm.DTO.PageDTO;
import com.shopx.base.dto.Result;
import com.shopx.base.utils.ResultUtil;
import com.shopx.base.exception.ShopxException;
import com.shopx.cm.bean.CmSend;
import com.shopx.cm.model.CmSendModel;
import com.shopx.cm.service.ICmSendService;

import com.shopx.base.anno.RepearSubmitChkAnno;
import com.shopx.core.common.CommonConstant;

import java.util.List;

/**
 * TODO
 *
 * @author lituo
 * @className: CmSendController
 * @date 2025-01-07
 */
@RestController
@Slf4j
@RequestMapping(value = "/cmSend")
public class CmSendController extends BaseController {

    @Resource
    private ICmSendService cmSendService;

    @PostMapping(value = "/queryPageList")
    @ShopxParamAnno
    @ShopxCheckParamAnno
    public Result<PageDTO> queryPageList(@RequestBody CmSendModel cmSend) throws ShopxException {
        PageDTO<CmSendModel> pageDTO = cmSendService.getListPage(cmSend);
        return ResultUtil.ok(pageDTO);
    }

    @PostMapping(value = "/insertOne")
    @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
    @ShopxParamAnno
    public Result<Integer> insertOne(@RequestBody CmSend cmSend) throws ShopxException {
        int result = cmSendService.insertSelective(cmSend);
        return ResultUtil.ok(result);
    }

    @PostMapping(value = "/updateOne")
    @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
    @ShopxParamAnno
    public Result<Integer> updateOne(@RequestBody CmSendModel cmSend) throws ShopxException {
        int result = cmSendService.updateByPrimaryKeySelective(cmSend);
        return ResultUtil.ok(result);
    }

    @PostMapping(value = "/queryOneByPrimaryKey")
    public Result<CmSendModel> queryOneByPrimaryKey(@RequestBody CmSend cmSend) throws ShopxException {
        CmSendModel result = cmSendService.selectByPrimaryKey(cmSend);
        return ResultUtil.ok(result);
    }


    @RequestMapping(value = "/download")
    public void download(CmSendModel cmSend, HttpServletResponse response) {
        ExcelObjectDTO dto = new ExcelObjectDTO();
        dto.setSubTitle("跟单数据【"+ DateTimeUtil.getDate8()+"】");
        dto.setTitle(new String[]{
                "cusId:客户编码",
                "cusName:姓名",
                "buildAddress:地址",
                "houseArea:外框面积",
                "designerName:设计师",
                "budgeterName:预算员",
                "materialName:材料员",
                "supervisor:监理",
                "mngName:项目经理/管家",
                "signDt:施工合同签订日期",
                "planDt:计划完工日期",
                "startDt:实际开工日期",
                "materialSubDt:选材单提交日期",
                "buildState:施工状况",
                "financeState:财务状况",
                "firstPayDt:交齐首付款日期",
                "midPayDt:交齐中期款日期",
                "bottomPayDt:交齐尾款日期",
                "startPayDt:交开工款日期",
                "contractMoney:合同金额",
                "payEngMoney:已收工程款",
                "buildRatio:开单比例",
                "czSupplier:瓷砖品牌",
                "czOrderDt:瓷砖下单日期",
                "czSendDt:瓷砖送货日期",
                "czCfDelayDays:瓷砖配置延期天数",
                "czDelayFlag:瓷砖是否延期",
                "czDelayDays:瓷砖耗时",
                "dlsSupplier:大理石品牌",
                "dlsOrderDt:大理石下单日期",
                "dlsSendDt:大理石送货日期",
                "dlsInstallDt:大理石安装日期",
                "dlsCfDelayDays:大理石配置延期天数",
                "dlsDelayFlag:大理石是否延期",
                "dlsDelayDays:大理石延期天数",
                "lhjmSupplier:铝合金门品牌",
                "lhjmOrderDt:铝合金门下单日期",
                "lhjmSendDt:铝合金门送货日期",
                "lhjmInstallDt:铝合金门安装日期",
                "lhjmCfDelayDays:铝合金门配置延期天数",
                "lhjmDelayFlag:铝合金门是否延期",
                "lhjmDelayDays:铝合金门耗时",
                "dzgSupplier:定制柜品牌",
                "dzgOrderDt:定制柜下单日期",
                "dzgSendDt:定制柜送货日期",
                "dzgInstallDt:定制柜安装日期",
                "dzgCfDelayDays:定制柜配置延期天数",
                "dzgDelayFlag:定制柜是否延期",
                "dzgDelayDays:定制柜耗时",
                "cgSupplier:橱柜品牌",
                "cgOrderDt:橱柜下单日期",
                "cgSendDt:橱柜送货日期",
                "cgInstallDt:橱柜安装日期",
                "cgCfDelayDays:橱柜配置延期天数",
                "cgDelayFlag:是否延期",
                "cgDelayDays:橱柜耗时",
                "kbSupplier:扣板品牌",
                "kbOrderDt:扣板下单日期",
                "kbSendDt:扣板送货日期",
                "kbInstallDt:扣板安装日期",
                "kbCfDelayDays:扣板配置延期天数",
                "kbDelayFlag:是否延期",
                "kbDelayDays:扣板耗时",
                "fmSupplier:房门品牌",
                "fmOrderDt:房门下单日期",
                "fmSendDt:房门送货日期",
                "fmInstallDt:房门安装日期",
                "fmCfDelayDays:房门配置延期天数",
                "fmDelayFlag:是否延期",
                "fmDelayDays:房门耗时",
                "jjSupplier:卫浴品牌",
                "jjOrderDt:卫浴下单日期",
                "jjSendDt:卫浴送货日期",
                "jjInstallDt:卫浴安装日期",
                "jjCfDelayDays:卫浴配置延期天数",
                "jjDelayFlag:卫浴是否延期",
                "jjDelayDays:卫浴耗时",
                "dbSupplier:木地板品牌",
                "dbOrderDt:木地板下单日期",
                "dbInstallDt:木地板安装日期",
                "dbCfDelayDays:木地板配置延期天数",
                "dbDelayFlag:木地板是否延期",
                "dbDelayDays:木地板耗时",
                "djSupplier:灯具品牌",
                "djOrderDt:灯具下单日期",
                "djSendDt:灯具送货日期",
                "djInstallDt:灯具安装天数",
                "djCfDelayDays:灯具配置延期天数",
                "djDelayFlag:灯具是否延期",
                "djDelayDays:灯具耗时",
                "kgSupplier:开关面板品牌",
                "kgOrderDt:开关面板下单日期",
                "kgSendDt:开关面板送货日期",
                "kgCfDelayDays:开关面板配置延期天数",
                "kgDelayFlag:开关面板是否延期",
                "kgDelayDays:开关面板耗时"});
        PageDTO<CmSendModel> pageDTO = cmSendService.getListPage(cmSend);
        dto.setObj(pageDTO.getData());
        dto.setSize(pageDTO.getiTotalDisplayRecords());
        ResultUtil.excelDownload(dto, response);
    }

    /**
     * 查询跟单状态报表数据
     * @param cmSend
     * @return
     * @throws ShopxException
     */
    @PostMapping(value = "/selectSendStateRpt")
    public Result<PageDTO> selectSendStateRpt(@RequestBody CmSendModel cmSend) throws ShopxException {
        PageDTO<CmSendStateDTO> pageDTO = new PageDTO();
        List<CmSendStateDTO> list = cmSendService.selectSendStateRpt(cmSend);
        pageDTO.setData(list);
        pageDTO.setiTotalDisplayRecords(list.size());
        return ResultUtil.ok(pageDTO);
    }

    /**
     * 查询财务状态报表
     * @param cmSend
     * @return
     * @throws ShopxException
     */
    @PostMapping(value = "/selectFinanceStateRpt")
    public Result<PageDTO> selectFinanceStateRpt(@RequestBody CmSendModel cmSend) throws ShopxException {
        PageDTO<CmStateDTO> pageDTO = new PageDTO();
        List<CmStateDTO> list = cmSendService.selectFinanceStateRpt(cmSend);
        pageDTO.setData(list);
        pageDTO.setiTotalDisplayRecords(list.size());
        return ResultUtil.ok(pageDTO);
    }

    /**
     * 查询施工状态报表
     * @param cmSend
     * @return
     * @throws ShopxException
     */
    @PostMapping(value = "/selectBuildStateRpt")
    public Result<PageDTO> selectBuildStateRpt(@RequestBody CmSendModel cmSend) throws ShopxException {
        PageDTO<CmStateDTO> pageDTO = new PageDTO();
        List<CmStateDTO> list = cmSendService.selectBuildStateRpt(cmSend);
        pageDTO.setData(list);
        pageDTO.setiTotalDisplayRecords(list.size());
        return ResultUtil.ok(pageDTO);
    }




	/*@PostMapping(value = "/deleteChecked")
	@RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
					@ShopxParamAnno
public Result<Integer> deleteChecked(@RequestBody CmSend cmSend) throws ShopxException {
		int result = cmSendService.deleteByPrimaryKey(cmSend);
		return ResultUtil.ok(result);
	}*/
}

